package com.meihua.shellapp.adapter;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aspsine.irecyclerview.IViewHolder;
import com.meihua.shellapp.R;
import com.meihua.shellapp.activity.GoodsSecondActivity;
import com.meihua.shellapp.bean.ProductIndexBean;
import com.meihua.shellapp.bean.ZhongAnBean;
import com.meihua.shellapp.utils.PicassoUtils;

import java.util.ArrayList;
import java.util.List;


public class InsuranceTypeRVAdapter extends RecyclerView.Adapter<IViewHolder> {
    private ArrayList<ProductIndexBean.DataBean.ProductBeanX> mData;
    private ArrayList<ProductIndexBean.DataBean.TypeIdBean> mImgData;


    Activity activity;

    public InsuranceTypeRVAdapter(ArrayList<ProductIndexBean.DataBean.ProductBeanX> mData, ArrayList<ProductIndexBean.DataBean.TypeIdBean> mImgData, Activity activity) {
        this.mData = mData;
        this.mImgData = mImgData;
        this.activity = activity;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    private OnItemClickListener mOnItemClickListener;

    @Override
    public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_goods_title, parent, false));
    }

    @Override
    public void onBindViewHolder(final IViewHolder holder, int position) {
        ((MViewHolder) holder).setData(position);
    }

    @Override
    public int getItemCount() {
        return mData != null ? mData.size() : 0;
    }

    class MViewHolder extends IViewHolder {
        public TextView mTitleTv;
        public TextView mMore;
        public ImageView mIV;
        RecyclerView recyclerView;

        public MViewHolder(View itemView) {
            super(itemView);
            mTitleTv = itemView.findViewById(R.id.item_title_tv);
            mMore = itemView.findViewById(R.id.item_title_more);
            recyclerView = itemView.findViewById(R.id.item_title_gv);
            mIV = itemView.findViewById(R.id.ins_iv);
            recyclerView.setLayoutManager(new GridLayoutManager(itemView.getContext(), 2));
        }

        public void setData(final int position) {
            if (position == 0) {
                mIV.setVisibility(View.VISIBLE);
                PicassoUtils.getInstance().bindImageData(mIV, mImgData.get(position).getCat_pic() + "");
//                Picasso.with(activity).load(Constant.IMGSTR + mImgData.get(position).getCat_pic()).placeholder(R.drawable.ic_default).into(mIV);
            } else {
                mIV.setVisibility(View.GONE);
            }

            mTitleTv.setText(mData.get(position).getCat_name());
            mMore.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    /*打开更多界面*/
                    Intent intent = new Intent(activity, GoodsSecondActivity.class);
                    intent.putExtra("id", mData.get(position).getId());
                    activity.startActivity(intent);
                }
            });
            ContantRVAdapter contantRVAdapter = new ContantRVAdapter(mData.get(position).getProduct(), activity);

            recyclerView.setAdapter(contantRVAdapter);
        }
    }
//    private List< ProductIndexBean.DataBean.ProductBeanX.ProductBean> addDataForBoss(List<ProductIndexBean.DataBean.ProductBeanX.ProductBean> data) {
//        List<ProductIndexBean.DataBean.ProductBeanX.ProductBean> tempData = new ArrayList<>();
//        ProductIndexBean.DataBean.ProductBeanX.ProductBean dataBean1 = new ProductIndexBean.DataBean.ProductBeanX.ProductBean();
//        dataBean1.setId("23333");
//        dataBean1.setProduct_name("尊享e生医疗保险（50万版）");
////        dataBean1.setPremium("99");//价格
////        dataBean1.setFit_member("30-60周岁");//	适合人群
////        dataBean1.setFeilv(new HomeIndexBean.DataBean.FeilvBean("30", "60", "一年"));//价格
//        tempData.add(dataBean1);
//
//        ProductIndexBean.DataBean.ProductBeanX.ProductBean dataBean2 = new ProductIndexBean.DataBean.ProductBeanX.ProductBean();
//        dataBean2.setId("23333");
//        dataBean2.setProduct_name("尊享无忧住院医疗");
////        dataBean2.setPremium("99");//价格
////        dataBean2.setFit_member("30-60周岁");//	适合人群
////        dataBean2.setFeilv(new ProductIndexBean.DataBean.ProductBeanX.ProductBean.FeilvBean("30", "60", "一年"));//价格
//        tempData.add(dataBean2);
//
//        ProductIndexBean.DataBean.ProductBeanX.ProductBean dataBean3 = new ProductIndexBean.DataBean.ProductBeanX.ProductBean();
//        dataBean3.setId("23333");
//        dataBean3.setProduct_name("癌症医疗保险");
////        dataBean3.setPremium("99");//价格
////        dataBean3.setFit_member("30-60周岁");//	适合人群
////        dataBean3.setFeilv(new ProductIndexBean.DataBean.ProductBeanX.ProductBean.FeilvBean("30", "60", "一年"));//价格
//        tempData.add(dataBean3);
//
//        ProductIndexBean.DataBean.ProductBeanX.ProductBean dataBean4 = new ProductIndexBean.DataBean.ProductBeanX.ProductBean();
//        dataBean4.setId("23333");
//        dataBean4.setProduct_name("个人综合意外保险");
////        dataBean4.setPremium("99");//价格
////        dataBean4.setFit_member("30-60周岁");//	适合人群
////        dataBean4.setFeilv(new ProductIndexBean.DataBean.ProductBeanX.ProductBean.FeilvBean("30", "60", "一年"));//价格
//        tempData.add(dataBean4);
//
//        ProductIndexBean.DataBean.ProductBeanX.ProductBean dataBean5 = new ProductIndexBean.DataBean.ProductBeanX.ProductBean();
//        dataBean5.setId("23333");
//        dataBean5.setProduct_name("糖尿病并发症保险");
////        dataBean5.setPremium("99");//价格
////        dataBean5.setFit_member("30-60周岁");//	适合人群
////        dataBean5.setFeilv(new ProductIndexBean.DataBean.ProductBeanX.ProductBean.FeilvBean("30", "60", "一年"));//价格
//        tempData.add(dataBean5);
//
//        ProductIndexBean.DataBean.ProductBeanX.ProductBean dataBean6 = new ProductIndexBean.DataBean.ProductBeanX.ProductBean();
//        dataBean6.setId("23333");
//        dataBean6.setProduct_name("尊享e生医疗保险（100万版）");
////        dataBean6.setPremium("99");//价格
////        dataBean6.setFit_member("30-60周岁");//	适合人群
////        dataBean6.setFeilv(new ProductIndexBean.DataBean.ProductBeanX.ProductBean.FeilvBean("30", "60", "一年"));//价格
//        tempData.add(dataBean6);
//
//        ProductIndexBean.DataBean.ProductBeanX.ProductBean dataBean7 = new ProductIndexBean.DataBean.ProductBeanX.ProductBean();
//        dataBean7.setId("23333");
//        dataBean7.setProduct_name("孝欣保 老年综合意外险");
////        dataBean7.setPremium("99");//价格
////        dataBean7.setFit_member("30-60周岁");//	适合人群
////        dataBean7.setFeilv(new HomeIndexBean.DataBean.FeilvBean("30", "60", "一年"));//价格
//        tempData.add(dataBean7);
////        tempData.addAll(data);
//        return tempData;
//    }
}
